package com.zrrd.yunchmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.yunchmall.product.service.IProductAttributeService;
import com.zrrd.yunchmall.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 商品属性参数表 前端控制器
 * </p>
 *
 * @author LiYe
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/productAttribute")
@Api(tags = "商品服务-商品属性模块")
public class ProductAttributeController {
    @Autowired
    private IProductAttributeService attributeService;
    //http://localhost:7000/shop-product/productAttribute/list/1?pageNum=1&pageSize=100&type=1
    @ApiOperation("查询列表")
    @GetMapping("/list/{attributeCateId}")
    public ResponseResult list(@PathVariable("attributeCateId") int cateId,
                               int pageNum,
                               int pageSize,
                               Integer type) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("product_attribute_category_id", cateId);
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return new ResponseResult(200, "查询成功",
                attributeService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }
}
